package com.cw.carwashcity.controller;

import com.cw.carwashcity.domain.DouArea;
import com.cw.carwashcity.service.DouAreaService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/douArea")
public class DouAreaController extends BaseController {
    @Autowired
    private DouAreaService douAreaService;

    /**
     * 查询地区列表
     */
    @GetMapping("/list")
    public List<DouArea> list(DouArea area) {
        List<DouArea> areas = douAreaService.selectAreaList(area);
        return areas;
    }

    /**
     * 获取地区详细信息
     */
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Integer areaId) {
        return success(douAreaService.selectAreaById(areaId));
    }

    /**
     * 新增地区
     */
    @PostMapping
    public AjaxResult add(@RequestBody DouArea area) {
        return toAjax(douAreaService.insertArea(area));
    }

    /**
     * 修改地区
     */
    @PutMapping
    public AjaxResult edit(@RequestBody DouArea area) {
        return toAjax(douAreaService.updateArea(area));
    }

    /**
     * 删除地区
     */
    @DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Integer[] areaIds) {
        return toAjax(douAreaService.deleteAreaByIds(areaIds));
    }

    @DeleteMapping("/{areaId}")
    public AjaxResult remove(@PathVariable Integer areaId) {
        return toAjax(douAreaService.deleteAreaById(areaId));
    }

    /**
     * 获取省份列表
     */
    @GetMapping("/provinces")
    public AjaxResult getProvinces() {
        List<DouArea> provinces = douAreaService.getProvinces();
        return AjaxResult.success(provinces);
    }

    /**
     * 获取城市列表
     */
    @GetMapping("/cities/{parentId}")
    public AjaxResult getCities(@PathVariable("parentId") Short parentId) {
        List<DouArea> cities = douAreaService.getCities(parentId);
        return AjaxResult.success(cities);
    }

    /**
     * 获取区县列表
     */
    @GetMapping("/districts/{parentId}")
    public AjaxResult getDistricts(@PathVariable("parentId") Short parentId) {
        List<DouArea> districts = douAreaService.getDistricts(parentId);
        return AjaxResult.success(districts);
    }
}
